<?php
/*#########################################*/
//    php网页版文件浏览器（编辑服务器配置用）
//    
//    作者：九天一声啸
//    邮箱：946585434@qq.com
//    日期：2020.8.10
//
/*#########################################*/

session_start(); //注意，此代码前不允许有任何输出，包括空白字符

$userEmail = '946585434@qq.com';
$md5Hash = '1deba7005ef24fffxxxxxxxxxxxxxxxx';
$passWord = '$2y$10$P8RrJNPX1BomMpQyRaeBhumxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$passwordLock = false;

//登陆判断
/*=====================*/
if(filter_input(INPUT_POST, "email", FILTER_SANITIZE_STRING)){
    if (password_verify($_POST['pwd'], $passWord)) {
        $passwordLock = true;
    } else {
        $passwordLock = false;
    }

    if(($userEmail === (string)$_POST['email']) && $passwordLock){
        $_SESSION['useremail'] = $md5Hash;
        echo '<script>location.href = "?page=view"</script>';
    }
}
/*=====================*/

//判断当前是否在登陆状态，否：去登陆；是：显示界面
/*=====================*/
if($_SESSION['useremail'] == $md5Hash){
    if($_GET['page'] != 'view'){
        echo '<script>location.href = "?page=view"</script>';
    }
}else{
    if($_GET['page'] != 'login'){
        echo '<script>location.href = "?page=login"</script>';
    }
}
/*=====================*/

//自动加载类文件
/*=====================*/
spl_autoload_register(function ($class) {
    include $class . 'Controller.class.php';
});
/*=====================*/

//根据变量 page 值加载相应的视图文件
/*=====================*/
include_once __DIR__ . '/header.php';
$page = htmlspecialchars($_GET['page'], ENT_QUOTES | ENT_HTML401);

if(file_exists(__DIR__ . '/' . $page . '.php')){
    $obj = new Manager;
    //加载到 view.php 视图文件的图标变量
    $person = $obj->icon['person'];
    include_once __DIR__ . '/' . $page . '.php';
}else{
    echo '无视图文件！';
}

include_once __DIR__ . '/footer.php'; 
/*=====================*/